package com.internship.javawebinternship.repository;

import com.internship.javawebinternship.entity.DailyReport;
import jakarta.transaction.Transactional;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface DailyReportRepository extends JpaRepository<DailyReport, String> {
    public List<DailyReport> findByStuempnoOrderByDateDesc(String no);

    public List<DailyReport> findByDateOrderByStuempnoDesc(String date);


    public List<DailyReport> findByReportid(String reportId);

    @Modifying
    @Transactional
    public int deleteByReportid(String reportId);


    @Transactional
    @Modifying
    //@Query(value = "select * from covid19.daily_report where isFever=:isfever AND isCough =:iscough",nativeQuery=true)
    @Query(value = "select * from covid19.daily_report where if(?1 !='',isFever=?1,1=1) " +
            "and if(?2!='',isCough=?2,1=1)and if(?3!='',temp>=?3,1=1)",nativeQuery = true)
    public  List<DailyReport> showSubmitByMul( String isfever,  String iscough,String temp);

    @Transactional
    @Modifying
    @Query(value = "select * from covid19.daily_report ORDER BY `date` desc",nativeQuery = true)
    public List<DailyReport> showAllSubmit();

    @Transactional
    @Modifying
    @Query(value = "select reportID,daily_report.stuEmpNo,`date`,`period`,temp,location,isFever,isCough from covid19.daily_report,covid19.student_info,covid19.tutor_classes where empNo =?1 and student_info.stuNo = daily_report.stuEmpNo and student_info.college = tutor_classes.college and student_info.profession = tutor_classes.profession and student_info.grade = tutor_classes.grade and student_info.classes = tutor_classes.classes  ORDER BY `stuNo` asc",nativeQuery = true)
    public List<DailyReport> showPartSubmit(String empNo);

}
